<?php

namespace app\api\model;

use Exception;
use think\facade\Db;
use think\facade\Log;
use think\Model;

class Order extends Model
{
    public static function getStatistic()
    {

        try {
            $result = [
                'today'      => Db::name('order')->whereTime('create_time', 'today')->field('COUNT(*) as count, SUM(money) as total')->where('status', 1)->find(),
                'month'      => Db::name('order')->whereTime('create_time', 'month')->field('COUNT(*) as count, SUM(money) as total')->where('status', 1)->find(),
                'last_month' => Db::name('order')->whereTime('create_time', 'last month')->field('COUNT(*) as count, SUM(money) as total')->where('status', 1)->find(),
                'total'      => Db::name('order')->field('COUNT(*) as count, SUM(money) as total')->where('status', 1)->find()
            ];
            return $result;
        } catch (Exception $e) {
            Log::warning('订单发送统计发送失败:' . $e->getMessage());
        }
    }
}
